package com.rd.student.jike.class2.xuezhixin.Work719;

public class Work01{


    public static void main(String[] args) {
        A a = new A();
        Thread1 thread1 = new Thread1(a);
        Thread2 thread2 = new Thread2(a);
        Thread3 thread3 = new Thread3(a);
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
class A{
    static volatile int i = 1;
    static boolean b = true;
    public static void add(){
        i++;
        if(i > 14){
            b = false;
        }
    }
}
class Thread1 extends Thread{
    A a;

    public Thread1(A a) {
        super();
        this.a = a;
    }

    @Override
    public void run() {
        while (a.b) {
            if ((A.i - 1) % 3 == 0) {
                System.out.print('A');
                A.add();
            }
        }
    }
}

class Thread2 extends Thread{
    A a;
    public Thread2(A a) {
        super();
        this.a = a;
    }

    @Override
    public void run() {
        while (a.b) {
            if ((A.i - 2) % 3 == 0) {
                System.out.print('B');
                A.add();
            }
        }
    }
}

class Thread3 extends Thread{
    A a;
    public Thread3(A a) {
        super();
        this.a = a;
    }

    @Override
    public void run() {
        while (a.b) {
            if ((A.i - 3) % 3 == 0) {
                System.out.print('C');
                A.add();
            }
        }
    }
}
